home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Storage / Bento / CM / ErrorRpt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  9.1 KB  |  195 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ErrorRpt.h
  3.  
  4.     Contains:    Container Manager Error Reporting Interfaces
  5.  
  6.     Written by:    Ira L. Ruben
  7.  
  8.     Owned by:    Ed Lai
  9.  
  10.     Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <2>     8/26/94    EL        #1181622 Ownership update.
  15.          <2>      5/9/94    MB        #1162181: Changes necessary to install MMM.
  16.          <1>      2/3/94    EL        first checked in
  17.  
  18.     To Do:
  19. */
  20.  
  21. /*---------------------------------------------------------------------------*
  22.  |                                                                           |
  23.  |                         <<<    ErrorRpt.h    >>>                          |
  24.  |                                                                           |
  25.  |                Container Manager Error Reporting Interfaces               |
  26.  |                                                                           |
  27.  |                               Ira L. Ruben                                |
  28.  |                                 12/06/91                                  |
  29.  |                                                                           |
  30.  |                  Copyright Apple Computer, Inc. 1991-1994                 |
  31.  |                           All rights reserved.                            |
  32.  |                                                                           |
  33.  *---------------------------------------------------------------------------*
  34.  
  35.  This file defines the stuff the Container Manager itself needs to report errors to the
  36.  user defined error handler.  The user never sees this stuff. The error reporting routines
  37.  defined in     CMErrOps.c      are provided as a convenience to allow the user to
  38.  convert error codes that we report to their corresponding messages.  The user need not
  39.  use them however.
  40. */
  41.  
  42. #ifndef __ERRORRPT__
  43. #define __ERRORRPT__
  44.  
  45. #ifndef __CMTYPES__
  46. #include "CMTypes.h"
  47. #endif
  48. #ifndef __CM_API_TYPES__
  49. #include "CMAPITyp.h"
  50. #endif
  51. #ifndef __CM_API_ERRNO__
  52. #include "CMAPIErr.h"            /* internally we always use    ErrorRpt.h    to get this    */
  53. #endif
  54. #ifndef __TOCENTRIES__
  55. #include "TOCEnts.h"   
  56. #endif
  57. #ifndef __TOCOBJECTS__
  58. #include "TOCObjs.h"   
  59. #endif
  60. #ifndef __CONTAINEROPS__
  61. #include "Containr.h"  
  62. #endif
  63. #ifndef __SESSIONDATA__
  64. #include "Session.h"          
  65. #endif
  66.  
  67.  
  68. /* To make it easier and more readable for the Container Manager to call the error             */
  69. /* reporter (whose pointer is in the session global data), the following macros are         */
  70. /* defined.  They take 0 to 5 inserts.  They all assume that the current container             */
  71. /* pointer is always contained in the variable named "container".                                                */
  72.  
  73. #define ERROR(n)                                                       (*SESSION->cmReportError)((CMErrorNbr)(n))
  74. #define ERROR1(n, i1)                                              (*SESSION->cmReportError)((CMErrorNbr)(n),    \
  75.                                                                                                                                                (char *)(i1))
  76. #define ERROR2(n, i1, i2)                                      (*SESSION->cmReportError)((CMErrorNbr)(n),    \
  77.                                                                                                                                              (char *)(i1),         \
  78.                                                                                                                                              (char *)(i2))
  79. #define ERROR3(n, i1, i2, i3)                              (*SESSION->cmReportError)((CMErrorNbr)(n),    \
  80.                                                                                                                                              (char *)(i1),        \
  81.                                                                                                                                              (char *)(i2),        \
  82.                                                                                                                                              (char *)(i3))
  83. #define ERROR4(n, i1, i2, i3, i4)                      (*SESSION->cmReportError)((CMErrorNbr)(n),    \
  84.                                                                                                                                              (char *)(i1),        \
  85.                                                                                                                                              (char *)(i2),        \
  86.                                                                                                                                              (char *)(i3),        \
  87.                                                                                                                                              (char *)(i4))
  88. #define ERROR5(n, i1, i2, i3, i4, i5)              (*SESSION->cmReportError)((CMErrorNbr)(n),    \
  89.                                                                                                                                              (char *)(i1),        \
  90.                                                                                                                                              (char *)(i2),        \
  91.                                                                                                                                              (char *)(i3),        \
  92.                                                                                                                                              (char *)(i4),        \
  93.                                                                                                                                              (char *)(i5))
  94.  
  95.  
  96. /* The following are the "moral equivalent" of the above, but access the error reporter    */
  97. /* directly through the session global data pointer. Just as the above assumed                    */
  98. /* "container" as the container pointer, here we assume "sessionData" is the session        */
  99. /* data pointer.  It is used by the macro SessionError defined in the header                        */
  100. /*      Session.h      which was included above.                                                                                */
  101.  
  102. #define SessionERROR(n)                                           SessionError((CMErrorNbr)(n))
  103. #define SessionERROR1(n, i1)                                  SessionError((CMErrorNbr)(n),    \
  104.                                                                                                                     (char *)(i1))
  105. #define SessionERROR2(n, i1, i2)                          SessionError((CMErrorNbr)(n),    \
  106.                                                                                                                     (char *)(i1),         \
  107.                                                                                                                     (char *)(i2))
  108. #define SessionERROR3(n, i1, i2, i3)                  SessionError((CMErrorNbr)(n),    \
  109.                                                                                                                     (char *)(i1),            \
  110.                                                                                                                     (char *)(i2),            \
  111.                                                                                                                     (char *)(i3))
  112. #define SessionERROR4(n, i1, i2, i3, i4)          SessionError((CMErrorNbr)(n),    \
  113.                                                                                                                     (char *)(i1),            \
  114.                                                                                                                     (char *)(i2),            \
  115.                                                                                                                     (char *)(i3),            \
  116.                                                                                                                     (char *)(i4))
  117. #define SessionERROR5(n, i1, i2, i3, i4, i5) SessionError((CMErrorNbr)(n),    \
  118.                                                                                                                     (char *)(i1),            \
  119.                                                                                                                     (char *)(i2),            \
  120.                                                                                                                     (char *)(i3),            \
  121.                                                                                                                     (char *)(i4),            \
  122.                                                                                                                     (char *)(i5))
  123.  
  124.  
  125. /* As a "safety valve" to try to protect the Container Manager, the following macro is     */
  126. /* called by every routine (possibly indirectly through the validate routines described    */
  127. /* later).  It effectively turns a routine into a "nop" (no operation) if                             */
  128. /* CMStartSession() was not called.  This is all we can do.  Without the error routine     */
  129. /* which is defined by CMStartSession() how do we tell the user anyway else?  Since         */
  130. /* this macro can be placed in functions that return a value, the macro parameter is         */
  131. /* used on the generated return statement.  The parameter must be the macro CM_NOVALUE     */
  132. /* when no value is to be returned.  This gets round the preprocessor's insistance on     */
  133. /* requiring an explicit macro parameter to a definition that has one!                                    */
  134.  
  135. #if CMVALIDATE
  136. #define NOPifNotInitialized(x) if (container == NULL || SESSION == NULL) return x
  137. #else
  138. #define NOPifNotInitialized(x)
  139. #endif
  140.  
  141. #define CM_NOVALUE                     /* NOPifNotInitialized(CM_NOVALUE) for functs with no value */
  142.  
  143. /* Note, the above macro assumes the standard convent we use everywhere in the Container*/
  144. /* Manager.  Namely, that the container refNum is always loaded into the variable                */
  145. /* "container".                                                                                                                                                    */
  146.  
  147. /* Caution -- the above test is NOT perfect!  If CMStartSession() is not called, the         */
  148. /* odds are that CMOpen[New]Container() will most likely blow.  They test for                     */
  149. /* CMStartSession() by checking the global data session pointer for NULL.  We also do     */
  150. /* that here as an added test.  If the user's session data pointer is indeed NULL, the     */
  151. /* open routines will return NULL for the container refNum.  Then we're safe!                        */
  152.  
  153.  
  154. /* The following are similar to NOPifNotInitialized(x) but are used to exit if we detect*/
  155. /* a bad object, property, type, or value.  The "x" has the same meaning as above.            */
  156.  
  157. #if CMVALIDATE
  158. #define ExitIfBadObject(o, x)     if (!cmValidateCMObject((CMObject)(o))) return x
  159. #define ExitIfBadProperty(p, x) if (!cmValidateCMProperty((CMObject)(p))) return x
  160. #define ExitIfBadType(t, x)         if (!cmValidateCMType((CMObject)(t))) return x
  161. #define ExitIfBadValue(v, x)       if (!cmValidateCMValue((CMValue)(v))) return x
  162. #else
  163. #define ExitIfBadObject(o, x)
  164. #define ExitIfBadProperty(p, x)
  165. #define ExitIfBadType(t, x)
  166. #define ExitIfBadValue(v, x)
  167. #endif
  168.  
  169. /* Note, that a NOPifNotInitialized() is implicit in these "ExitIfBad..." calls.  So         */
  170. /* NOPifNotInitialized() does not need to be used if there is at least one "                        */
  171. /* "ExitIfBad..." call.                                                                                                                                    */
  172.  
  173.  
  174. /* The following macros are used to get the container type name passed when the                    */
  175. /* container was opened.  This may be used for error message inserts.  See the comments    */
  176. /* for CMReturnContainerName() below for additional info on this.   These macros, like     */
  177. /* the ERRORn() macros always assume that the container pointer is in a variable named     */
  178. /* "container".  A more general TYPENAMEx is also provided where you do supply the             */
  179. /* container pointer.                                                                                                                                        */
  180.  
  181. #define TYPENAME                           TYPENAMEx(container)
  182. #define TYPENAMEx(container) ((char *)(((ContainerPtr)container)->metaHandlerProc->typeName))
  183.  
  184.  
  185. /* The following macros are the counterparts to TYPENAME and TYPENAMEx above.  But here */
  186. /* the macros expand to calls to CMReturnContainerName() (which, by the way, is a                */
  187. /* handler macro defined in Handlers.h).  These are the ones that should be used for         */
  188. /* error inserts.  The TYPENAME and TYPENAMEx macros are actually only used by                     */
  189. /* CMReturnContainerName() when no name handler is provided.                                                        */
  190.     
  191. #define CONTAINERNAME                            CONTAINERNAMEx(container)
  192. #define CONTAINERNAMEx(container)    ((char *)CMReturnContainerName((CMContainer)container))
  193.  
  194. #endif
  195.